﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SoundCapture;


namespace GentlyWeep
{
	/// <summary>
	/// Interaction logic for CaptureDevice.xaml
	/// </summary>
	public partial class CaptureDevice : Window
    {
        SoundCaptureDevice[] devices;

        public CaptureDevice()
        {
            this.InitializeComponent();

            LoadDevices();
        }
        

        public SoundCaptureDevice SelectedDevice
        {
            get { return devices[DeviceBox.SelectedIndex]; }
        }


        private void LoadDevices()
        {
            DeviceBox.Items.Clear();

            int defaultDeviceIndex = 0;
            devices = SoundCaptureDevice.GetDevices();
            for (int i = 0; i < devices.Length; i++)
            {
                DeviceBox.Items.Add(devices[i].Name);
                if (devices[i].IsDefault)
                    defaultDeviceIndex = i;
            }
            DeviceBox.SelectedIndex = defaultDeviceIndex;
        }

        private void deviceNamesListBox_DoubleClick(object sender, EventArgs e)
        {
            if (DeviceBox.SelectedIndex < 0) return;

            this.DialogResult = true;
            this.Close();
        }


        private void listen(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DeviceBox.SelectedIndex < 0) return;

            this.DialogResult = true;
            this.Close();
        }
	}
}